/*
Copyright (c) 2019 Alibaba Group Holding Limited

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

*/
#include "stdio.h"
#include "vtimer.h"
#include "datatype.h"




// int flashInit();
// int flashID(unsigned int* flashID);
// int flashProgram(char* dst, char *src, int length);
// int flashRead(char* dst, char *src, int length);
// int flashErase(char *dst, int length);
// int flashChipErase();
void flashTest();

int g_rwBuffer[4 * 1024];
int g_dstAddress = 0;
int g_length = 0;
/**
 * The engineering-driven operation error return
 */
int g_error = 0;

#define UNKNOWN    0           // Unknown
#define ONCHIP     1           // On-chip Flash Memory
#define EXT8BIT    2           // External Flash Device on 8-bit  Bus
#define EXT16BIT   3           // External Flash Device on 16-bit Bus
#define EXT32BIT   4           // External Flash Device on 32-bit Bus
#define EXTSPI     5           // External Flash Device on SPI






/**
 * The definition of functional options,
 * 0 corresponds to check id,1 corresponds
 * to program,2 corresponds to read,3 corresponds
 * to erase,4 corresponds to chip erase.
 */
int g_func = 0;
unsigned int g_flashID = 0;



// __attribute((noinline)) void __bkpt_label() {
// 	asm("");
// }


int tee_main (void)
{

	//init_flashdevice(&FlashDevices);

	// call nor flash drivers to program
	//g_error = flashInit();

	// for debug flash driver
	flashTest();

	// do {
	// 	__bkpt_label();
	// 	switch (g_func) {
	// 	case 0:
	// 		g_error = flashID(&g_flashID);
	// 		break;
	// 	// case 1:
	// 	// 	g_error = flashProgram((char *) g_dstAddress, (char *) g_rwBuffer,
	// 	// 			g_length);
	// 	// 	break;
	// 	// case 2:
	// 	// 	g_error = flashRead((char *) g_rwBuffer, (char *) g_dstAddress,
	// 	// 			g_length);
	// 	// 	break;
	// 	// case 3:
	// 	// 	g_error = flashErase((char *) g_dstAddress, g_length);
	// 	// 	break;
	// 	// case 4:
	// 	// 	g_error = flashChipErase();
	// 	// 	break;
	// 	default:
	// 		break;
	// 	}
	// } while (1);
	sim_end();




}

int ree_main (void)
{

    printf("dma test successfully\n");
    sim_end();
}




